package com.example.controller;

import com.example.entity.Dept;
import com.example.service.DeptService;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.bind.annotation.RestController;

import java.util.List;
import java.util.concurrent.TimeUnit;

/**
 * @author: 21050134
 * @date: 2023/9/12 16:07
 * @description:服务提供者的控制层
 */
@RestController
@Slf4j
public class DeptController {
	@Autowired
	private DeptService deptService;

	@Value("${server.port}")
	private String serverPort;

	@RequestMapping(value="/dept/get/{id}",method = RequestMethod.GET)
	public Dept get(@PathVariable("id") int id){
		return deptService.get(id);
	}

	@RequestMapping(value="/dept/list",method = RequestMethod.GET)
	public List<Dept> list(){
		return deptService.selectAll();
	}

	@RequestMapping(value="/dept/feign/timeout")
	public String DeptFeignTimeout(){
		try{
			TimeUnit.SECONDS.sleep(5);
		}catch (InterruptedException e){
			e.printStackTrace();
		}
		return serverPort;
	}
}
